import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _isFunction from "lodash/isFunction";

var _dec, _class;

/**
 * DropPage
 * @date 2018/10/10
 */
import React from 'react';
import { DropTarget } from 'react-dnd';
import intl from 'utils/intl';
import { DropType, DragType } from "../../config";
import styles from "../index.less?modules";
var dropPageSpec = {
  drop: function drop(props, monitor) {
    var _monitor$getItem = monitor.getItem(),
        dragOrDrawDragComponent = _monitor$getItem.component;

    var dragType = monitor.getItemType();

    if (dragType === DragType.dragComponent) {
      var onAddComponent = props.onAddComponent;

      if (_isFunction(onAddComponent)) {
        onAddComponent(dragOrDrawDragComponent);
      }
    } else if (dragType === DragType.DrawDragComponent) {
      var onMoveComponent = props.onMoveComponent;

      if (_isFunction(onMoveComponent)) {
        onMoveComponent(dragOrDrawDragComponent);
      }
    }
  }
};

var dropPageCollect = function dropPageCollect(connect, monitor) {
  var connectDropTarget = connect.dropTarget();
  var isOver = monitor.isOver();
  var canDrop = monitor.canDrop();
  var draggingColor = monitor.getItemType();
  return {
    connectDropTarget: connectDropTarget,
    isOver: isOver,
    canDrop: canDrop,
    draggingColor: draggingColor
  };
};

var DropPage = (_dec = DropTarget(DropType.draw, dropPageSpec, dropPageCollect), _dec(_class = /*#__PURE__*/function (_React$Component) {
  _inherits(DropPage, _React$Component);

  var _super = _createSuper(DropPage);

  function DropPage(props) {
    var _this;

    _classCallCheck(this, DropPage);

    _this = _super.call(this, props);
    _this.handleActivePage = _this.handleActivePage.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(DropPage, [{
    key: "handleActivePage",
    value: function handleActivePage() {
      var onActiveComponent = this.props.onActiveComponent;

      if (_isFunction(onActiveComponent)) {
        // 激活当前编辑窗口为 Page
        onActiveComponent();
      }
    }
  }, {
    key: "render",
    value: function render() {
      var connectDropTarget = this.props.connectDropTarget;
      return connectDropTarget && connectDropTarget( /*#__PURE__*/React.createElement("div", {
        className: styles['drop-page-more'],
        onClick: this.handleActivePage
      }, intl.get('cpfm.ui.message.field.operateDes').d('拖入更多组件|点击切换左侧组件为容器')));
    }
  }]);

  return DropPage;
}(React.Component)) || _class);
export default DropPage;